package 优先级队列_堆;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * https://leetcode-cn.com/problems/last-stone-weight/
 */
public class 最后一块石头的重量 {
    public int lastStoneWeight(int[] stones) {
        List<Integer> list = new ArrayList();
        for (int i = 0; i < stones.length; i++) {
            list.add(stones[i]);
        }
        return choiceReturn(list).get(0);

    }
    public List<Integer> choiceReturn(List<Integer> curStone){
        if (curStone.size() == 1 ) {
            return curStone;
        }
        if (curStone.size() == 0){
            curStone.add(0);
            return curStone;
        }
        Collections.sort(curStone);
        int maxOne = curStone.get(curStone.size() - 1);
        int maxTwo = curStone.get(curStone.size() - 2);
        if (maxOne == maxTwo){
            Collections.sort(curStone);
            curStone.remove(curStone.size() - 1);
            curStone.remove(curStone.size() - 1);

        }else {
            Collections.sort(curStone);
            int curNum = curStone.get(curStone.size() - 1) - curStone.get(curStone.size() - 2);
            curStone.remove(curStone.size() - 1);
            curStone.remove(curStone.size() - 1);
            curStone.add(curNum);

        }
        choiceReturn(curStone);
        return curStone;
    }
}
